package com.github.postsanf.yinian.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.github.postsanf.yinian.R;
import com.github.postsanf.yinian.constants.ACTIONs;
import com.umeng.analytics.MobclickAgent;

public class MyWalletChongZhiDialogActivity extends Activity implements View.OnClickListener {
    public View mMenuView;
    private InputMethodManager imm;
    private RelativeLayout rl_tixian1;
    private RelativeLayout rl_tixian2;
    private TextView to_pay_cash;
    private EditText getcash_num;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.pop_to_pay_zidingyi2);
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        initView();
        getcash_num.setFocusable(true);
        getcash_num.setFocusableInTouchMode(true);
        getcash_num.requestFocus();
        getcash_num.setSelection(getcash_num.getText().length());
        imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
    }


    private void initView() {
        findViewById(R.id.mywallet_leftback).setOnClickListener(this);
        findViewById(R.id.to_pay_close).setOnClickListener(this);
        rl_tixian1 = (RelativeLayout) findViewById(R.id.rl_tixian1);
        rl_tixian2 = (RelativeLayout) findViewById(R.id.rl_tixian2);
        to_pay_cash = (TextView) findViewById(R.id.to_pay_cash);
        getcash_num = (EditText) findViewById(R.id.getcash_num);
        getcash_num.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getcash_num.setSelection(getcash_num.getText().length());
            }
        });
        rl_tixian1.setOnClickListener(this);
        getcash_num.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (s.length() > 0) {
                    rl_tixian2.setVisibility(View.VISIBLE);
                    rl_tixian1.setVisibility(View.GONE);
                    to_pay_cash.setBackgroundResource(R.drawable.btn_topay_sure_press);
                    if (Integer.parseInt(s.toString()) > 200) {
                        Toast.makeText(MyWalletChongZhiDialogActivity.this, "充值金额两百以内", Toast.LENGTH_SHORT).show();
//                        getcash_num.setEnabled(false);
                        return;
                    }
                } else {
                    to_pay_cash.setBackgroundResource(R.drawable.btn_topay_sure);
//                    getcash_num.setEnabled(true);
                }
            }
        });
    }

    @Override
    public void onBackPressed() {

    }


    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.to_pay_close:
                sendBroadcast(new Intent(ACTIONs.actionCloseactivity));
                finish();
                break;
            case R.id.mywallet_leftback:
                finish();
                break;
            case R.id.rl_tixian1:
                rl_tixian2.setVisibility(View.VISIBLE);
                rl_tixian1.setVisibility(View.GONE);
                getcash_num.setFocusable(true);
                getcash_num.setFocusableInTouchMode(true);
                getcash_num.requestFocus();
                getcash_num.setSelection(getcash_num.getText().length());
//                imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
                break;
        }
    }


    // 友盟统计
    public void onResume() {
        super.onResume();
        MobclickAgent.onPageStart(this.getClass().getSimpleName());
        MobclickAgent.onResume(this);
    }

    public void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd(this.getClass().getSimpleName());
        MobclickAgent.onPause(this);
    }

}
